package xq.gwt.ui.crud;

import xq.gwt.mvc.model.AbstractEntityModel;
import xq.gwt.mvc.model.CommandModel;
import xq.gwt.mvc.model.EntityModel;
import xq.gwt.mvc.model.PropertyModel;

public class FilterModel extends AbstractEntityModel {
		
	private static final long serialVersionUID = -1732020134852213887L;
	private PropertyModel fieldValue;
	private Operator operator = Operator.equals;	
	private String title;	
	private FilterModelList childClauses = new FilterModelList();

	

    public FilterModel(){
		
	}
	
	public FilterModel(PropertyModel fieldValue){
		this.fieldValue = fieldValue;
	}
	@Override
	public String getTitle() {		
		return title;
	}

	public void setTitle(String title){
		this.title = title;
	}
	
	@Override
	public PropertyModel[] getProperties() {
		if(fieldValue != null){
			return new PropertyModel[] {fieldValue};
		}else {
			return null;
		}	
		
	}

	@Override
	public CommandModel[] getCommands() {		
		return null;
	}
	
		
	public PropertyModel getFieldValue() {
		return fieldValue;
	}

	public void setFieldValue(PropertyModel fieldValue) {
		this.fieldValue = fieldValue;
	}

	public Operator getOperator() {
		return operator;
	}

	public void setOperator(Operator operator) {
		this.operator = operator;
	}


	public FilterModelList getChildClauses() {
		return childClauses;
	}
	
	
	
	public boolean isComposite(){
		if(childClauses.size() != 0)
			return true;
		else 
			return false;
	}

	

	public enum Operator {
		equals, notEquals, from, to, is, isNot, in, notIn,greaterThan, lessThan, contains, NotContains, like, notLike
	}



	@Override
	public EntityModel newInstance() {		
		return new FilterModel();
	}

}
